package com.atguigu.lease.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;


public enum BaseStatus implements BaseEnum {


    ENABLE(1, "正常"),

    DISABLE(0, "禁用");


    @EnumValue
    @JsonValue
    private Integer code;

    private String name;

    BaseStatus(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getName() {
        return this.name;
    }
    // 根据code获取枚举实例
    public static AppointmentStatus fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (AppointmentStatus status : AppointmentStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的预约状态码: " + code);
    }

    // 根据名称获取枚举实例（不区分大小写）
    public static AppointmentStatus fromName(String name) {
        if (name == null || name.trim().isEmpty()) {
            return null;
        }
        for (AppointmentStatus status : AppointmentStatus.values()) {
            if (status.name().equalsIgnoreCase(name)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的预约状态名称: " + name);
    }
}
